package com.gujiangbo.thread;

import java.util.concurrent.TimeUnit;

/**
 * HookThread 钩子线程
 *
 * @author gujiangbo
 */
public class HookThreadTest {

    public static void main(String[] args) {

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println(" the hook thread-1  is running ....");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(" the hook thread-1  will exit.");
        }));


        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println(" the hook thread-2 is running ....");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(" the hook thread-2  will exit.");
        }));

    }
}
